#usr/bin/python
from PyQt4 import QtGui, QtCore
import canvas

class Peak_Widget(QtGui.QDialog):
	
	def __init__(self, peak, parent = None):
		QtGui.QDialog.__init__(self, parent)
		self.peak =peak

		self.setupUi()
		
	def setupUi(self):
	
		#self.setMaximumSize(200,200)
		lst = ["transition", "RT", "intensity", "RT_min", "RT_max"]
		lst_combo = ["associated spectra", "associated chromatogram", "3D view"]
		model =QtGui.QStandardItemModel(1,2, self)
		model.setHorizontalHeaderLabels(lst)
		transition = QtGui.QStandardItem(str(self.peak.get_trans().toString()))
		rt_ =QtGui.QStandardItem(str(self.peak.get_rt()))
		rt_min=QtGui.QStandardItem(str(self.peak.get_rt_min()))
		rt_max=QtGui.QStandardItem(str(self.peak.get_rt_max()))
		area =QtGui.QStandardItem(str(self.peak.get_area()))
		
		model.setItem(0,0, transition)
		model.setItem(0,1, rt_)
		model.setItem(0,2, area)
		model.setItem(0,3, rt_min)
		model.setItem(0,4, rt_max)
		
		rt =[p.get_x() for p in self.peak.get_data()]
		intensity =[p.get_y() for p in self.peak.get_data()]

		
		self.main_layout =QtGui.QVBoxLayout(self)
		self.table = QtGui.QTableView(self)
		self.table.setModel(model)
		self.table.resizeRowsToContents()
		self.table.resizeColumnsToContents()
		self.table.setMaximumHeight(50)
		
		self.canvas =canvas.canvasUi ( [rt], [intensity], flags ="peak", parent =self )
		#sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Maximum, QtGui.QSizePolicy.Maximum)
		#self.canvas.setSizePolicy(sizePolicy)
		self.main_layout.addWidget(self.canvas)
		self.main_layout.addWidget(self.table)
		#self.table.show()
		#self.canvas.show()
		self.hl2 =  QtGui.QHBoxLayout()
		self.button= QtGui.QPushButton("plot")
		self.combobox =QtGui.QComboBox(self)
		for el in lst_combo:
			self.combobox.addItem(el)
		self.hl2.addWidget(self.combobox)
		self.hl2.addWidget(self.button)
		self.main_layout.addLayout(self.hl2)
		
if __name__=="__main__":
	from core import objects as obj
	import sys
	app = QtGui.QApplication(sys.argv)
	#(self,transition, rt, rtmin, rtmax, area, chromatogram = None, points = None):
	p =obj.chromatoPeak(obj.MS2_trans((0,0)), 156, 152, 165, 123544, points=[obj.Data2D(156,9000),obj.Data2D(158,12000),obj.Data2D(167,6000)])
	widget = Peak_Widget(p)
	widget.show()
	app.exec_()
	
